<%@ page import="java.text.DateFormat" %>
<%@ page import="java.util.Date" %>
<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/19
  Time: 14:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Operation</title>
</head>
<body>
<!-- 聊天业务逻辑-->
<%
    request.setCharacterEncoding("UTF-8");
    //获取用户名，用户名要拼接在发送的消息的前面
    String username=session.getAttribute("username").toString();
    //获取application中记录
    String info="";
    Object o=application.getAttribute("info");
    if(o!=null){
        info=o.toString();
    }
    //1.获取要发送的内容
    String sendInfo=request.getParameter("sendInfo").toString();
    if(sendInfo==null){
        request.setAttribute("flage","YES");
        request.getRequestDispatcher("chatRoom.jsp").forward(request, response);
        //response.sendRedirect("chatRoom.jsp");
    }
    //前后内容拼接
    info = info + username+ "("+DateFormat.getTimeInstance().format(new Date())+"): "+ "<span style='color:red'>"+sendInfo+"</span></br>";
    //zhangsan:(19:20:06) 你好

    //2.将获取的内容存到application中
    application.setAttribute("info",info);
    //3.重定向跳转到chatRoom.jsp
    response.sendRedirect("chatRoom.jsp");
%>

</body>
</html>
